<script>
	import Vue from 'vue'
	import {cities, getlocation} from '@/utils/api/public.js'
	export default {
		onLaunch: function() {
			// uni.setStorageSync('tarbarModule','1')
			console.warn('当前组件仅支持 uni_modules 目录结构 ，请升级 HBuilderX 到 3.1.0 版本以上！')
			let sysInfo = uni.getSystemInfoSync();
			console.log(sysInfo,'-')
			Vue.prototype.statusBarHeight = sysInfo.statusBarHeight;
			Vue.prototype.pageHeight = sysInfo.safeArea.height - sysInfo.statusBarHeight -sysInfo.safeAreaInsets.bottom
			Vue.prototype.bottomHeight = sysInfo.safeAreaInsets.bottom
			// #ifdef MP-WEIXIN
			let rect = uni.getMenuButtonBoundingClientRect()
			Vue.prototype.navBarHeight = (rect.top - sysInfo.statusBarHeight) * 2 + rect.height;
			Vue.prototype.jWidth = rect.width
			// #endif
			// #ifndef MP-WEIXIN
			Vue.prototype.navBarHeight = 44
			// #endif
			console.log('App Launch')
			uni.getLocation({
				success:(res)=>{
					let arr = []
					let latitude = res.latitude
					let longitude = res.longitude
					getlocation({lat:res.latitude,lng:res.longitude}).then(data=>{
						console.log(data,'=-')
						
						let obj = {
							province:encodeURIComponent(data.data.regeocode.addressComponent.province),
							city:encodeURIComponent(data.data.regeocode.addressComponent.city),
							district:encodeURIComponent(data.data.regeocode.addressComponent.district),
							lng:res.longitude,
							lat:res.latitude
						}
						
						
					})
					
					cities().then(res=>{
						res.data.cities.forEach(e=>{
							e.children.forEach(s=>{
								let item = JSON.parse(JSON.stringify(s))
								let lat = Number(item.lat)
								let lng = Number(item.lng)
								if(latitude>lat-0.2&&latitude<lat+0.2&&longitude>lng-0.2&&longitude<lng+0.2){
									arr.push(s)
								}
							})
						})
						uni.setStorageSync('select_city',arr[0]?JSON.stringify(arr[0]):'')
						uni.$emit('updateCart')
						// console.log(arr,'--')
					})
				}
			})
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '@/uni_modules/uni-scss/index.scss';
	/* #ifndef APP-NVUE */
	@import '@/static/customicons.css';
	@import "@/style/css/index.scss";
	
	// 设置整个项目的背景色
	page {
		background-color: #ffffff;
	}
	
	// padding-bottom: constant(safe-area-inset-bottom);
	// padding-bottom: env(safe-area-inset-bottom);
	
	/* #endif */
	
	page {
		background-color: #F8F8F8;
	}
	*{
		font-family: PingFang SC, PingFang SC;
		font-style: normal;
		text-transform: none;
	}
	/deep/ .input-tip{
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 34rpx;
		color: #999999 !important;
		// line-height: 76rpx;
		font-style: normal;
		text-transform: none;
	}
	// .tarbar_page{
	// 	padding-bottom: calc(constant(safe-area-inset-bottom) + 100rpx) !important;
	// 	padding-bottom: calc(env(safe-area-inset-bottom) + 100rpx) !important;
	// }
	
	.one-row{
		display: block;
		overflow: hidden;
		/**（文字长度超出限定宽度，则隐藏超出的内容）**/
		white-space: nowrap;
		/**（设置文字在一行显示，不能换行）**/
		text-overflow: ellipsis;
	}
	.more-row{
		 word-break: break-all;
		text-overflow: ellipsis;
		overflow: hidden;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: var(--row-num); /* 这里是超出几行省略 */
	}
	
	.pb-con{
		padding-bottom: constant(safe-area-inset-bottom) !important;
		padding-bottom: env(safe-area-inset-bottom) !important;
	}
	
	.box-1{
		/deep/ uni-switch .uni-switch-input:before{
		    background-color: #ccc !important;
		}
	} 
	
	image{
		display: block;
	}
	
	button{
		margin: 0;
		padding: 0;
		text-align: center;
		border: none;
		&::after{
			border: none;
		}
	}
	
	.example-info {
		font-size: 14px;
		color: #333;
		padding: 10px;
	}
	
	.popup-box{
		.bottom{
			/deep/ .bgF{
				border-radius: 16rpx 16rpx 0 0 !important;
				overflow: hidden;
				// position: relative;
				.uni-popup__wrapper{
					border-radius: 16rpx 16rpx 0 0 !important;
				}
			}
		}
	}
	.bgHui{
		/deep/ .bgF{
			background-color: #F8F8F8 !important;
			position: relative;
			.uni-popup__wrapper{
				background-color: #F8F8F8 !important;
			}
		}
	}
	.button{
		background: linear-gradient( 132deg, #FFA233 0%, #FB4C4C 100%);
		border-radius: 48rpx 48rpx 48rpx 48rpx;
		font-size: 24rpx;
		color: #ffffff;
	}
</style>
